package main

import (
	"fmt"
	"go-the-way-of-learning/day11/2log_transfer/conf"
	"go-the-way-of-learning/day11/2log_transfer/es"
	"go-the-way-of-learning/day11/2log_transfer/kafka"
	"gopkg.in/ini.v1"
)

// 日志数据从kafka取出发送es

func main() {
	// 加载配置文件
	var cfg conf.LogTransfer
	err := ini.MapTo(&cfg, "day11/2log_transfer/conf/cfg.ini")
	if err != nil {
		fmt.Printf("ini config failed, err: %v\n", err)
		return
	}

	// 初始化es
	err = es.Init(cfg.EsCfg.Address)
	if err != nil {
		fmt.Printf("init es client failed, err: %v\n", err)
		return
	}
	fmt.Println("init es success")

	// 初始化kafka, 读取消息发送es
	err = kafka.Init([]string{cfg.KafkaCfg.Address}, cfg.KafkaCfg.Topic)
	if err != nil {
		fmt.Printf("init kafka comsumer failed, err: %v\n", err)
		return
	}
	select {}
}
